package com.iflytek.view;
import util1.QingYunkeRobotServiceImpl;
import util1.Response;
import com.iflytek.cloud.speech.Setting;
import com.iflytek.cloud.speech.SpeechUtility;
import com.iflytek.util.Version;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;
public class MeTest extends JFrame implements ActionListener {
     String words;
   /* static String input_words;
    static{
        //创建青云客的机器人实现类
        QingYunkeRobotServiceImpl qingyunkeRobotService = new QingYunkeRobotServiceImpl();
        Scanner scanner = new Scanner(System.in);
            String mText = scanner.nextLine();
            Response response = qingyunkeRobotService.answer(mText);
            try {
               words=  new String(response.getContent().getBytes(), "UTF-8").replace("{br}", "\n");

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }*/

    private JPanel mMainJpanel;
    private JPanel mContentPanel;
    private static JFrame mJframe;

    private JButton jbtnRecognize;
    private JButton jbtnGrammar;
    private JButton jbtnSynthesize;

    private static final long serialVersionUID = 1L;
    public MeTest(String words) {
        this.words=words;
        // 初始化
        StringBuffer param = new StringBuffer();
        param.append( "appid=" + Version.getAppid() );
        SpeechUtility.createUtility( param.toString() );
        Setting.setShowLog(false);

        // 设置界面大小，背景图片
        ImageIcon background = new ImageIcon("res/index_bg.png");
        JLabel label = new JLabel(background);
        label.setBounds(0, 0, background.getIconWidth(),
                background.getIconHeight());
        getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
        int frameWidth = background.getIconWidth();
        int frameHeight = background.getIconHeight();

        setSize(frameWidth, frameHeight);//框体的宽高与背景颜色宽高一样
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     /*   //直接上语音听写
        ImageIcon imgSynthesize = new ImageIcon("res/btn_synthesize.png");
        jbtnSynthesize = this.createImageButton(imgSynthesize);
        jbtnSynthesize.setBounds(460, 150, imgSynthesize.getIconWidth(),
                imgSynthesize.getIconHeight());
        DrawableUtils.setMouseListener(jbtnSynthesize, "res/btn_synthesize");
        GridLayout gridlayout = new GridLayout(0, 1);
        gridlayout.setHgap(10);
        mMainJpanel = new JPanel(gridlayout);//面板里设置布局
        mMainJpanel.setOpaque(false);//控件不透明

        mMainJpanel.add(jbtnSynthesize);//面板里加入按钮
        jbtnSynthesize.addActionListener(this);//执行点击事件*/

        mContentPanel = new JPanel(new BorderLayout());
        mContentPanel.setOpaque(false);
        //内容面板里放入主面板

//        mContentPanel.add(mMainJpanel, BorderLayout.CENTER);

        setLocationRelativeTo(null);

        setContentPane(mContentPanel);
        mContentPanel.add(new TtsSpeechView(words));
//        mContentPanel.add(new MyTest1());
        setVisible(false);

    }
    public JPanel getMainJpanel() {
        return mMainJpanel;
    }

    public JPanel getContePanel() {
        return mContentPanel;
    }

   /* public static void main(String[] args) {
        new MeTest("啦啦啦啦");
    }*/
    public JButton createImageButton(ImageIcon img) {
        JButton button = new JButton("");
        button.setIcon(img);
        button.setSize(img.getIconWidth(), img.getIconHeight());
        button.setBackground(null);

        button.setBorder(null);
        button.setContentAreaFilled(false);
        button.setFocusPainted(false);

        return button;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jbtnSynthesize) {
//            mContentPanel.remove(mMainJpanel);

//            mContentPanel.revalidate();
//            mContentPanel.repaint();
        }
    }
}
